//
//  MapDetailViewController.m
//  成都咖啡
//
//  Created by rimi on 16/4/7.
//  Copyright © 2016年 wenhao. All rights reserved.
//

#import "MapDetailViewController.h"
#import <MapKit/MapKit.h>
#import "mapAnnatation.h"

@interface MapDetailViewController ()<MKMapViewDelegate>
@property(nonatomic,strong)MKMapView * mapview;
@property(nonatomic,strong)UIImageView * imageview;
@property(nonatomic,strong)UIView * titleView;
@property(nonatomic,strong)UIButton * buttonReturn;
@property(nonatomic,strong)UIButton * rightButton;
@end

@implementation MapDetailViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.mapview];
    [self.view addSubview:self.titleView];
    self.mapview.delegate =self;
    [self.view addSubview:self.buttonReturn];
    [self.view addSubview:self.rightButton];
    CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(30.629793, 104.102868);
    mapAnnatation *annotation = [[mapAnnatation alloc] init];
    annotation.coordinate = coordinate;
    annotation.title = @"成都市高新区孵化园";
    
    
    
    [self.mapview addAnnotation:annotation];
    [self.mapview setRegion:MKCoordinateRegionMakeWithDistance(coordinate, 2000, 2000)];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
    //    MKAnnotationView * ann = [[MKAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"123"];
    //    ann.leftCalloutAccessoryView = [[UIView alloc]initWithFrame:CGRectMake(50, 200, 60, 30)];
    //    [annotation.imageview addSubview:ann];
    MKAnnotationView *newAnnotation=[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"annotation1"];
    UIButton * annbutton= [UIButton buttonWithType:UIButtonTypeSystem];
    annbutton.frame = CGRectMake(0, 0, 30, 30);
    annbutton.backgroundColor = [UIColor redColor];
    annbutton.imageView.image = [UIImage imageNamed:@"iconfont-xinlinghuayuan"];
    [annbutton addTarget:self action:@selector(respondsAnnbutton:) forControlEvents:UIControlEventTouchUpInside];
    newAnnotation.rightCalloutAccessoryView =annbutton;
    newAnnotation.image = [UIImage imageNamed:@"Location_Pin_32px_1187228_easyicon.net"];
    
    
    
    newAnnotation.canShowCallout=YES;
    return newAnnotation;
}

-(void)respondsAnnbutton:(UIButton * )sender
{
    NSLog(@"返回了店铺信息页面");
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (MKMapView * )mapview
{
    if (!_mapview) {
        _mapview = [[MKMapView alloc]initWithFrame:CGRectMake(0,64, self.view.frame.size.width, self.view.frame.size.height)];
    }
    return _mapview;
}
- (UIView * )titleView
{
    if (!_titleView) {
        _titleView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 64)];
        _titleView.backgroundColor = [UIColor redColor];
        
    }
    return _titleView;
}


- (UIButton * )buttonReturn
{
    if (!_buttonReturn) {
        _buttonReturn = [UIButton buttonWithType:UIButtonTypeSystem];
        _buttonReturn.frame = CGRectMake(20, 20,40, 25);
        _buttonReturn.titleLabel.text =@"返回";
        
        _buttonReturn.backgroundColor = [UIColor yellowColor];
        [_titleView addSubview:_buttonReturn];
        [_buttonReturn addTarget:self action:@selector(respondsToReturn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _buttonReturn;
}
- (UIButton * )rightButton
{
    if (!_rightButton) {
        _rightButton =[UIButton buttonWithType:UIButtonTypeSystem];
        _rightButton.frame = CGRectMake(300, 20, 40, 25);
        _rightButton.titleLabel.text = @"导航";
          _rightButton.backgroundColor = [UIColor yellowColor];
        [_titleView addSubview:_rightButton];
      
        [_rightButton addTarget:self action:@selector(respondstoDaoHang:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _rightButton;
}
-(void)respondstoDaoHang:(UIButton * )sender
{
    NSLog(@"hgjkl");
}
-(void)respondsToReturn:(UIButton*)sender{
    [self.navigationController popViewControllerAnimated:YES];
}

@end
